﻿using UnityEngine;

public class InputCtrler : MonoBehaviour
{
    private void FixedUpdate()
    {
        bool isDown = false;
        Vector3 mousePos = Vector3.zero;
        if (Input.GetMouseButtonDown(0))
        {
            isDown = true;
            mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        }
        else if (Input.touchCount > 0)
        {
            isDown = true;
            Debug.Log(Input.touches[0].position);
            mousePos = Camera.main.ScreenToWorldPoint(Input.touches[0].position);
        }
        if (isDown)
        {
            Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);
            RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero, 100, 1<<LayerMask.NameToLayer("Logo"));
            if (hit.collider != null)
            {
                var icon = hit.collider.GetComponent<Icon>();
                if (icon != null)
                {
                    icon.MouseDown();
                }
            }
        }

    }

}